package 链表.单向.练习;
//删除单向链表中所有重复出现的节点

public class Text_10 {
    public ListNode deleteDuplication(ListNode head){
        ListNode newhead = new ListNode();
        ListNode tmphead = newhead;
        ListNode cur = head;
        while (cur!=null){
         if(cur.next!=null && cur.val ==cur.next.val){
            //一直走到不重复的节点
            while (cur.next!=null && cur.val ==cur.next.val){
                cur = cur.next;
            }
            cur = cur.next;
        }else {
            tmphead.next = cur;
            tmphead = tmphead.next;
            cur = cur.next;
        }
    }
        //万一末位也是重复，但是指向还有数据
        tmphead.next =null;
        return newhead.next;
    }
}
